package command.client;

import client.ClientSession;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.MessageCommunication;

public class DisconnectUserClient implements CommandClient {

    public DisconnectUserClient() {
    }

    @Override
    public void execute(ClientSession clientSession, boolean isInvokedByTheServer) {
        try {
            if (isInvokedByTheServer) {
                Object tmp = clientSession.getObjectInputStream().readObject();
                MessageCommunication message = (MessageCommunication) tmp;
                if (message.getStatus()) {
                    clientSession.closeSession();
                }
            } else {
            }
        } catch (ClassNotFoundException | IOException ex) {
            Logger.getLogger(DisconnectUserClient.class.getName()).log(Level.SEVERE,
                    "Fallo al realizar la desconexión del cliente con el servidor", ex);
        }
    }
}
